home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcr / pcr4_4.lha / DIST / debugnub / CirioNubStart.c < prev    next >
C/C++ Source or Header  |  1992-03-06  |  8KB  |  330 lines

  1. /* begincopyright
  2.   Copyright (c) 1988 Xerox Corporation. All rights reserved.
  3.   Use and copying of this software and preparation of derivative works based
  4.   upon this software are permitted. Any distribution of this software or
  5.   derivative works must comply with all applicable United States export
  6.   control laws. This software is made available AS IS, and Xerox Corporation
  7.   makes no warranty about the software, its performance or its conformity to
  8.   any specification. Any person obtaining a copy of this software is requested
  9.   to send their name and post office or electronic mail address to:
  10.     PCR Coordinator
  11.     Xerox PARC
  12.     3333 Coyote Hill Rd.
  13.     Palo Alto, CA 94304
  14.   endcopyright */
  15.  
  16. /*
  17.  * CirioNubStart.c
  18.  *
  19.  * Demers, January 11, 1991 8:24:18 am PST
  20.  * Udagawa, December 28, 1990 11:32:58 pm PST
  21.  *
  22.  * This file calls XR_setjmp, so it can't be optimized.
  23.  */
  24.  
  25. #include "xr/Errno.h"
  26. #include "xr/Threads.h"
  27. #include "xr/ThreadsBackdoor.h"
  28. #include "xr/ThreadsSignalsPrivate.h"
  29.  
  30. #include "xr/ThreadsMsg.h"
  31.  
  32. #include "xr/CirioNubProtocol.h"
  33. #include "xr/CirioNubPrivate.h"
  34. #include "xr/CirioNubInstall.h"
  35. #include "xr/CirioNubEnvironment.h"
  36. #include "xr/CirioNubProcs.h"
  37.  
  38. #define RESCHED_SELF    1
  39.  
  40. struct CirioNubState cns;
  41.  
  42.  
  43. /*
  44.  * signal handlers
  45.  */
  46.  
  47. static int reschedSigs[] = XR_RESCHED_SIGS;
  48. static int memerrSigs[] = XR_MEMERR_SIGS;
  49. static int interruptSigs[] = XR_INTR_SIGS;
  50.  
  51.  
  52. static void
  53. CirioNubReschedHandler(sig, code, scp, addr)
  54.     int sig;
  55.     int code;
  56.     struct sigcontext *scp;
  57.     char *addr;
  58. {
  59.     XR_SlaveCheckOrders();
  60. }
  61.  
  62.  
  63. static void
  64. CirioNubInterruptHandler(sig, code, scp, addr)
  65.     int sig;
  66.     int code;
  67.     struct sigcontext *scp;
  68.     char *addr;
  69. {
  70.     cns.cns_gotSig = TRUE;
  71. }
  72.  
  73.  
  74. static void
  75. CirioNubMemerrHandler(sig, code, scp, addr)
  76.     int sig;
  77.     int code;
  78.     struct sigcontext *scp;
  79.     char *addr;
  80. {
  81.     int mask;
  82.     int *p;
  83.  
  84.     if( !cns.cns_memerrJmpBufValid )
  85.         XR_Panic("CirioNubMemerrHandler jmp buf invalid");
  86.     mask = sigblock(0);
  87.     for( p = &(memerrSigs[0]); *p != 0; p++ ) mask &= (~(*p));
  88.     sigsetmask(mask);
  89.     (void)XR_longjmp(&(cns.cns_memerrJmpBuf), 1);
  90. }
  91.  
  92.  
  93. /*
  94.  * init proc -- executed on slave IOP
  95.  */
  96.  
  97. static void
  98. CirioNubInitialize(clientData)
  99.     unsigned clientData;
  100. {
  101.     struct sigvec vec;
  102.     struct sigvec ovec;
  103.     int *p;
  104.  
  105.     cns.cns_gotSig = 0;
  106.  
  107.     /* Install resched handler */
  108.     vec.sv_handler = CirioNubReschedHandler;
  109.     vec.sv_mask = 0;
  110.     vec.sv_flags = SV_INTERRUPT;
  111.     for( p = reschedSigs; *p != 0; p++ ) {
  112.     if( sigvec(*p, &vec, &ovec) != 0 )
  113.         XR_Panic("CirioNubInitialize: sigvec failed (resched)");
  114.     }
  115.  
  116.     /* Install interrupt handler */
  117.     vec.sv_handler = CirioNubInterruptHandler;
  118.     vec.sv_mask = 0;
  119.     vec.sv_flags = SV_INTERRUPT;
  120.     for( p = interruptSigs; *p != 0; p++ ) {
  121.     if( sigvec(*p, &vec, &ovec) != 0 )
  122.         XR_Panic("CirioNubInitialize: sigvec failed (interupt)");
  123.     }
  124.  
  125.     if( XR_setjmp(&(cns.cns_memerrJmpBuf)) != 0 )
  126.     XR_Panic("CirioNubInitialize: target of longjmp");
  127.  
  128.     /* Install memerr handler */
  129.     vec.sv_handler = CirioNubMemerrHandler;
  130.     vec.sv_mask = 0;
  131.     vec.sv_flags = SV_INTERRUPT;
  132.     for( p = memerrSigs; *p != 0; p++ ) {
  133.     if( sigvec(*p, &vec, NIL) != 0 )
  134.         XR_Panic("CirioNubInitialize: sigvec failed (memerr)");
  135.     }
  136. }
  137.  
  138. /*
  139.  * memory access tester
  140.  */
  141.  
  142. bool
  143. CirioNubCanAccess(p, nBytes, write)
  144.     char *p;
  145.     int nBytes;
  146.     bool write;
  147. {
  148.     int i, x;
  149.  
  150.     if( XR_setjmp(&(cns.cns_memerrJmpBuf)) == 0 ) {
  151.         cns.cns_memerrJmpBufValid = TRUE;
  152.         if( write ) {
  153.             for( i = 0; i < nBytes; i++ ) {
  154.                 x = *p; *p++ = x;
  155.             }
  156.         } else {
  157.             for( i = 0; i < nBytes; i++ ) {
  158.                 x = *p++;
  159.             }
  160.         }
  161.         cns.cns_memerrJmpBufValid = FALSE;
  162.         return TRUE;
  163.     } else {
  164.         cns.cns_memerrJmpBufValid = FALSE;
  165.         return FALSE;
  166.     }
  167. }
  168.  
  169.  
  170. /*
  171.  * Kick proc
  172.  */
  173.  
  174. void
  175. CirioNubKickDebuggee()
  176. {
  177.     int i;
  178. #   if (!RESCHED_SELF)
  179.         int my_pid = getpid();
  180. #   endif
  181.  
  182. #   ifdef UNDEFINED_pgrp
  183.         (void) killpg(XR_sysArea->sa_pgrpVP, reschedSigs[0]);
  184. #   else
  185.         for( i = 0; i < XR_sysArea->sa_numVP; i++ ) {
  186.             int pid = XR_sysArea->sa_vpe[i].vpe_pid;
  187.             if( pid != 0 )
  188.                 (void) kill(pid, reschedSigs[0]);
  189.         }
  190. #   endif
  191.  
  192.     for( i = 0; i < XR_sysArea->sa_numIOP; i++ ) {
  193.         int pid = XR_sysArea->sa_iope[i].iope_pid;
  194.         if( pid == 0 ) continue;
  195. #       if (!RESCHED_SELF)
  196.             if( pid == my_pid ) continue;
  197. #       endif
  198.         (void) kill(pid, reschedSigs[0]);
  199.     }
  200. }
  201.  
  202.  
  203.  
  204. /*
  205.  * start proc -- executed in a thread
  206.  */
  207.  
  208. static int
  209. CirioNubStartUnconditionally()
  210. {
  211.     CirioNubHandle h;
  212.     int ans;
  213.     int port;
  214.     char *portEnv;
  215.     char *printConsoleMessagesEnv;
  216.     extern char *(getenv());
  217.     extern int atoi();
  218.  
  219.     h = CirioNubGetDefaultHandle( 128, 6*1024 );
  220.     if( h == NIL ) {
  221.         XR_ErrorVMsg "CirioNubStart no slave available\n");
  222.         return (-99);
  223.     }
  224.  
  225.     (void)CirioNubRegisterCProc(h,
  226.         CirioNubProcID_Null, CirioNubServeNull);
  227.     (void)CirioNubRegisterCProc(h,
  228.         CirioNubProcID_WaitSig, CirioNubServeWaitSig);
  229.     (void)CirioNubRegisterCProc(h,
  230.         CirioNubProcID_SetDBStat, CirioNubServeSetDBStat);
  231.     (void)CirioNubRegisterCProc(h,
  232.         CirioNubProcID_GetBytes, CirioNubServeGetBytes);
  233.     (void)CirioNubRegisterCProc(h,
  234.         CirioNubProcID_PutBytes, CirioNubServePutBytes);
  235.     (void)CirioNubRegisterCProc(h,
  236.         CirioNubProcID_GetWords16, CirioNubServeGetWords16);
  237.     (void)CirioNubRegisterCProc(h,
  238.         CirioNubProcID_PutWords16, CirioNubServePutWords16);
  239.     (void)CirioNubRegisterCProc(h,
  240.         CirioNubProcID_GetWords32, CirioNubServeGetWords32);
  241.     (void)CirioNubRegisterCProc(h,
  242.         CirioNubProcID_PutWords32, CirioNubServePutWords32);
  243.     (void)CirioNubRegisterCProc(h,
  244.         CirioNubProcID_GetThreads, CirioNubServeGetThreads);
  245.     (void)CirioNubRegisterCProc(h,
  246.         CirioNubProcID_PCtoInfo, CirioNubServePCtoInfo);
  247.     (void)CirioNubRegisterCProc(h,
  248.         CirioNubProcID_KillWorld, CirioNubServeKillWorld);
  249.  
  250.  
  251.     (void)CirioNubRegisterCProc(h,
  252.         CirioNubProcID_IssueThreadCommand,
  253.         CirioNubServeIssueThreadCommand);
  254.     (void)CirioNubRegisterCProc(h,
  255.         CirioNubProcID_GetDBStat, CirioNubServeGetDBStat);
  256.     (void)CirioNubRegisterCProc(h,
  257.         CirioNubProcID_GetFileEntry, CirioNubServeGetFileEntry);
  258.     (void)CirioNubRegisterCProc(h,
  259.         CirioNubProcID_LookupSymEntryByName,
  260.         CirioNubServeLookupSymEntryByName);
  261.     (void)CirioNubRegisterCProc(h,
  262.         CirioNubProcID_LookupSymEntryByValue,
  263.         CirioNubServeLookupSymEntryByValue);
  264.     (void)CirioNubRegisterCProc(h,
  265.         CirioNubProcID_LookupSymEntryByID,
  266.         CirioNubServeLookupSymEntryByID);
  267.     (void)CirioNubRegisterCProc(h,
  268.         CirioNubProcID_SkipSymEntryByName,
  269.         CirioNubServeSkipSymEntryByName);
  270.     (void)CirioNubRegisterCProc(h,
  271.         CirioNubProcID_SkipSymEntryByValue,
  272.         CirioNubServeSkipSymEntryByValue);
  273.     (void)CirioNubRegisterCProc(h,
  274.         CirioNubProcID_GetMatchingSymEntryByName,
  275.         CirioNubServeGetMatchingSymEntryByName);
  276.     (void)CirioNubRegisterCProc(h,
  277.         CirioNubProcID_GetMatchingSymEntryByValue,
  278.         CirioNubServeGetMatchingSymEntryByValue);
  279.  
  280.     (void)CirioNubRegisterCProc(h,
  281.         CirioNubProcID_GetMaxThreads,
  282.         CirioNubServeGetMaxThreads);
  283.  
  284.     (void)CirioNubRegisterCProc(h,
  285.         CirioNubProcID_GetThreadFromCTRep,
  286.         CirioNubServeGetThreadFromCTRep);
  287.  
  288.     (void)CirioNubRegisterCProc(h,
  289.         CirioNubProcID_GetInstrSetAndOpSys,
  290.         CirioNubServeGetInstrSetAndOpSys);
  291.  
  292.     port = 0;
  293.     if( (portEnv = getenv("CirioPort")) != NIL ) {
  294.         port = atoi(portEnv);
  295.         if( (port < 4096) || (port >= 8192) ) port = 0;
  296.     }
  297.     if( (printConsoleMessagesEnv = getenv("CirioPrintConsoleMessages"))
  298.             != NIL ) {
  299.         cns.cns_printConsoleMessages = 1;
  300.     }
  301.     XR_NormalVMsg "CirioNubInstall v %d ", CIRIO_NUB_PROCS_VERSION );
  302.     ans = CirioNubInstall(h, port, CirioNubInitialize, 0);
  303.     XR_NormalVMsg "... returns %d\n", ans);
  304.     return ans;
  305. }
  306.  
  307. static bool XR_cirioNubStarted = FALSE;
  308.  
  309. int
  310. XR_run_CirioNub()
  311. {
  312.     if( ! XR_cirioNubStarted ) {
  313.         XR_cirioNubStarted = TRUE;
  314.         return CirioNubStartUnconditionally();
  315.     }
  316.     return (-1);
  317. }
  318.  
  319. int
  320. CirioNubStart()
  321. {
  322.     return XR_run_CirioNub();
  323. }
  324.  
  325. int
  326. XR_run_DebugNub()
  327. {
  328.     return XR_run_CirioNub();
  329. }
  330.